


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;

public class IOManager {
	
	private String PATH_FILE;
	
	public IOManager(String PATH_FILE){
		this.PATH_FILE=PATH_FILE;
	}

	
	/**
	 * lecture du fichier 
	 * @return iterator d'un tableau contenant les lignes du fichier 
	 */
	public Iterator<String> readIterator() throws IOException{

		// ArrayList qui contiendra une cellule par ligne du fichier
		ArrayList<String> lineArray = new ArrayList<String>();
		
		FileInputStream fileInput = new FileInputStream(PATH_FILE);
		InputStreamReader fileReader = new InputStreamReader(fileInput);
		BufferedReader buffer = new BufferedReader(fileReader);
		String line; // Variable temporaire stockant la ligne
		while ((line = buffer.readLine()) != null) {
			lineArray.add(line);
		}
		buffer.close();
		return lineArray.iterator(); // Retourne le tableau de ligne(s)
	}
	
	/**
	 * lecture du fichier 
	 * @return String  contenant toutes les lignes du fichier 
	 */
	public String readString() throws IOException{
		String chaine="";
		
		FileInputStream fileInput = new FileInputStream(PATH_FILE);
		InputStreamReader fileReader = new InputStreamReader(fileInput);
		BufferedReader buffer = new BufferedReader(fileReader);
		String line; // Variable temporaire stockant la ligne
		while ((line = buffer.readLine()) != null) {
			chaine+=line;
		}
		buffer.close();
		return chaine; // Retourne le tableau de ligne(s)
	}

	/**
	 * Ecriture du fichier de sortie
	 * @param path of the file to write and the chaine to write
	 */ 
	public void write(String chaine) throws IOException{

		FileWriter fw = new FileWriter (PATH_FILE);
		BufferedWriter bw = new BufferedWriter (fw);
		PrintWriter fichierSortie = new PrintWriter (bw); 
		fichierSortie.print (chaine); 
		fichierSortie.close();

	}

	public void writebite(byte[] array) throws IOException{
		/*OutPutBitStream out = new OutputBitStream(new FileOutputStream(PATH_FILE));
		out.write(array,0,array.length);
		out.close();*/
		
	}
}
